import requestMeeting, { request } from '@/plugins/axios'
import { SearchListItem, VmpEntity, VmpMemberEntity } from './interface'

/** 获取画面合成信息 */
export const fetchGetVmpParams = async (meeting_moid: string) =>
	requestMeeting<VmpEntity>({
		url: `/mcc/${meeting_moid}/vmps/1`,
		method: 'get',
	}).then((res) => res)

/** 开始画面合成 */
export const fetchStartVmp = async (meeting_moid: string, data: any) =>
	requestMeeting({
		url: `/mcc/${meeting_moid}/vmps`,
		method: 'post',
		data: data,
	}).then((res) => res)

/** 停止画面合成 */
export const fetchStopVmp = async (meeting_moid: string) =>
	requestMeeting({
		url: `/mcc/${meeting_moid}/vmps/1`,
		method: 'delete',
	}).then((res) => res)

/** 改变画面合成 */
export const fetchChangeVmp = async (meeting_moid: string, data: any) =>
	requestMeeting({
		url: `/mcc/${meeting_moid}/vmps/1`,
		method: 'PUT',
		data: data,
	}).then((res) => res)

/** 获取画面合成预案列表 */
export const fetchGetVmpPlanList = async (meetingMoid: string) =>
	requestMeeting<
		{
			layout: number
			id: string
			mode: number
			name: string
		}[]
	>({
		url: `/meetings/${meetingMoid}/prevmps?count=0`,
		method: 'get',
	}).then((res) => res)

/** 载入画面合成预案 */
export const fetchGetVmpPlan = async (meetingMoid: string, id: string) =>
	request<VmpEntity>({
		url: `/meetings/${meetingMoid}/prevmps/${id}?type=1`,
		method: 'get',
	}).then((res) => res)

/** 删除画面合成预案 */
export const fetchDeleteVmpPlan = async (meetingMoid: string, id: string) =>
	requestMeeting({
		url: `/meetings/${meetingMoid}/prevmps/${id}`,
		method: 'delete',
	}).then((res) => res)

/** 编辑画面合成预案 */
export const fetchEditVmpPlan = async (meetingMoid: string, id: string, data: any) =>
	requestMeeting({
		url: `/meetings/${meetingMoid}/prevmps/${id}`,
		method: 'POST',
		data: JSON.stringify(data),
	}).then((res) => res)

/** 保存画面合成预案 */
export const fetchSaveVmpPlan = async (meetingMoid: string, data: any) =>
	requestMeeting({
		url: `/meetings/${meetingMoid}/prevmps`,
		method: 'POST',
		data: JSON.stringify(data),
	}).then((res) => res)

/** 获取单通道轮询信息 */
export const fetchGetVmpSinglePoll = async (meeting_moid: string) =>
	request<{ list: VmpMemberEntity[] }>({
		url: `/mcc/${meeting_moid}/vmps/1/members/poll`,
		method: 'get',
	}).then((res) => res)

/** 获取搜索的关键字 */
export const fetchGetDialogSearchResult = async (meeting_moid: string, value: string) =>
	request<{ list: SearchListItem[] }>({
		url: `/mcc/${meeting_moid}/mts/search`,
		method: 'get',
		params: {
			key: value,
		},
	}).then((res) => (res.success && res.list ? res.list : undefined))
